// Implements the frame which holds all the UI surrounding the map
// HARDCODED!
package
{
  import flare.display.TextSprite;
  
  import flash.display.Sprite;
  import flash.events.*;

  public class Frame extends Sprite
  {
    
    private var _dimx:int;
    private var _dimy:int;
    private var _bgcolor:uint;
    private var _innercolor:uint;
    
  	private var background:Sprite;
  	
  	private var toolbarbg:Sprite;
  	
  	private var title:TextSprite;
  	
  	// large boxes
  	private var greenBox:Sprite;
  	private var blueBox:Sprite;
  	private var purpleBox:Sprite;
  	
  	// medium boxes
  	private var pinkBox:Sprite;
  	private var brownBox:Sprite;
  	private var yellowBox:Sprite;
  	
  	// small medium boxes
  	private var orangeBox:Sprite;
  	private var redBox:Sprite;
  	
  	// small boxes
  	private var grayBox:Sprite;
  	private var blackBox:Sprite;
  	private var whiteBox:Sprite;
    
    public function Frame(dimx:int, dimy:int, bgcolor:uint, innercolor:uint)
    {
    	
    	_dimx = dimx;
    	_dimy = dimy;
    	_bgcolor = bgcolor;
    	_innercolor = innercolor;
    	
    	background = new Sprite();
    	addChild(background);
    	
    	toolbarbg = new Sprite();
    	addChild(toolbarbg);
    	
    	greenBox = new Sprite();
    	addChild(greenBox);
    	
      blueBox = new Sprite();
    	addChild(blueBox);
    	
    	purpleBox = new Sprite();
    	addChild(purpleBox);
    	
    	pinkBox = new Sprite();
    	addChild(pinkBox);
    	
    	brownBox = new Sprite();
    	addChild(brownBox);
    	
    	yellowBox = new Sprite();
    	addChild(yellowBox);
    	
    	orangeBox = new Sprite();
    	addChild(orangeBox);
    	
      redBox = new Sprite();
    	addChild(redBox);
    	
      grayBox = new Sprite();
    	addChild(grayBox);
    	
      blackBox = new Sprite();
    	addChild(blackBox);
    	
      whiteBox = new Sprite();
    	addChild(whiteBox);
    	
    	title = new TextSprite();
    	addChild(title);
    	
    	drawFrame();

    }
    
    public function drawFrame():void{
      drawBackground(_bgcolor);
      drawTitle(0x000000);
      drawToolbarBackground(0x000000);
      drawBoundingBoxes(_innercolor);
    }
    
    private function drawTitle(color:uint):void{
      
    	title.text = "Visualizing common color terms";
    	title.size = 20;
    	title.color = color;
    	title.font = "Calibri";
    	title.x = 5;
    	title.y = 2;
    	
    }
    
    public function drawBackground(color:uint):void{
      
      background.graphics.clear();
    	background.graphics.beginFill(color);
    	background.graphics.drawRect(0, 0, _dimx, _dimy);
    	background.graphics.endFill();
    	
    }
    
    private function drawToolbarBackground(color:uint):void{
      
      toolbarbg.graphics.clear();
      toolbarbg.graphics.beginFill(color, 0.6);
      toolbarbg.graphics.drawRect(_dimx - 200, 35, 195, _dimy-5-35);
      toolbarbg.graphics.endFill();
      
    }
    
    public function drawBoundingBoxes(color:uint):void{
      
      var border_color:uint = 0x777777;
      
      if(color == 0x000000){
        border_color = 0x222222;
        drawTitle(0x777777);
        drawToolbarBackground(0x333333);
      }
      else if(color == 0xffffff){
        border_color = 0xcccccc;
        drawTitle(0x000000);
        drawToolbarBackground(0x555555);
      }
      else if(color == 0x797979){
        border_color = 0x555555;
        drawTitle(0x000000);
        drawToolbarBackground(0x000000);
      }
      
      // large boxes
      greenBox.graphics.clear();
      greenBox.graphics.lineStyle(1, border_color);
      greenBox.graphics.beginFill(color);
      greenBox.graphics.drawRect(5, 35, _dimx - 200 - 10, 110);
      greenBox.graphics.endFill();
      
      greenBox.graphics.beginFill(0x008800);
      greenBox.graphics.drawRect(5 + _dimx-200-10 - 70, 35+110 - 16, 70, 16);
      greenBox.graphics.endFill();
      
      blueBox.graphics.clear();
    	blueBox.graphics.lineStyle(1, border_color);
      blueBox.graphics.beginFill(color);
      blueBox.graphics.drawRect(5, 35 + 110 + 10*1, _dimx - 200 - 10, 110);
      blueBox.graphics.endFill();
      
      blueBox.graphics.beginFill(0x0000ff);
      blueBox.graphics.drawRect(5 + _dimx-200-10 - 70, 35+110*2 + 10 - 16, 70, 16);
      blueBox.graphics.endFill();
      
      purpleBox.graphics.clear();
    	purpleBox.graphics.lineStyle(1, border_color);
      purpleBox.graphics.beginFill(color);
      purpleBox.graphics.drawRect(5, 35 + 110*2 + 10*2, _dimx - 200 - 10, 110);
      purpleBox.graphics.endFill();
      
      purpleBox.graphics.beginFill(0x7D00DD);
      purpleBox.graphics.drawRect(5 + _dimx-200-10 - 70, 35+110*3 + 10*2 - 16, 70, 16);
      purpleBox.graphics.endFill();
    	
    	// medium boxes
    	
    	pinkBox.graphics.clear();
    	pinkBox.graphics.lineStyle(1, border_color);
      pinkBox.graphics.beginFill(color);
      pinkBox.graphics.drawRect(5, 35 + 110*3 + 10*3, _dimx - 200 - 10, 110);
      pinkBox.graphics.endFill();
      
      pinkBox.graphics.beginFill(0xFF817B);
      pinkBox.graphics.drawRect(5 + _dimx-200-10 - 70, 35+110*4 + 10*3 - 16, 70, 16);
      pinkBox.graphics.endFill();

      brownBox.graphics.clear();
    	brownBox.graphics.lineStyle(1, border_color);
      brownBox.graphics.beginFill(color);
      brownBox.graphics.drawRect(5, 35 + 110*4 + 10*4, _dimx - 200 - 10, 75);
      brownBox.graphics.endFill();
      
      brownBox.graphics.beginFill(0x5F3100);
      brownBox.graphics.drawRect(5 + _dimx-200-10 - 70, 35+110*4 + 75 + 10*4 - 16, 70, 16);
      brownBox.graphics.endFill();

      yellowBox.graphics.clear();
    	yellowBox.graphics.lineStyle(1, border_color);
      yellowBox.graphics.beginFill(color);
      yellowBox.graphics.drawRect(5, 35 + 110*4 + 75 + 10*5, _dimx - 200 - 10, 75);
      yellowBox.graphics.endFill();
      
      yellowBox.graphics.beginFill(0xFFDE00);
      yellowBox.graphics.drawRect(5 + _dimx-200-10 - 70, 35+110*4 + 75*2 + 10*5 - 16, 70, 16);
      yellowBox.graphics.endFill();
    	
    	// small medium boxes
    	
    	orangeBox.graphics.clear();
    	orangeBox.graphics.lineStyle(1, border_color);
    	orangeBox.graphics.beginFill(color);
    	orangeBox.graphics.drawRect(5, 35 + 110*4 + 75*2 + 10*6, _dimx - 200 - 10, 40);
    	orangeBox.graphics.endFill();
    	
    	orangeBox.graphics.beginFill(0xFF8400);
      orangeBox.graphics.drawRect(5 + _dimx-200-10 - 70, 35+110*4 + 75*2 + 40 + 10*6 - 16, 70, 16);
      orangeBox.graphics.endFill();

      redBox.graphics.clear();
    	redBox.graphics.lineStyle(1, border_color);
    	redBox.graphics.beginFill(color);
    	redBox.graphics.drawRect(5, 35 + 110*4 + 75*2 + 40 + 10*7, _dimx - 200 - 10, 40);
    	redBox.graphics.endFill();
    	
    	redBox.graphics.beginFill(0xFF0000);
      redBox.graphics.drawRect(5 + _dimx-200-10 - 70, 35+110*4 + 75*2 + 40*2 + 10*7 - 16, 70, 16);
      redBox.graphics.endFill();

    	// small boxes
    	
    	grayBox.graphics.clear();
    	grayBox.graphics.lineStyle(1, border_color);
    	grayBox.graphics.beginFill(color);
    	grayBox.graphics.drawRect(5, 35 + 110*4 + 75*2 + 40*2 + 10*8, _dimx - 200 - 10, 40);
    	grayBox.graphics.endFill();
    	
    	grayBox.graphics.beginFill(0x777777);
      grayBox.graphics.drawRect(5 + _dimx-200-10 - 70, 35+110*4 + 75*2 + 40*3 + 10*8 - 16, 70, 16);
      grayBox.graphics.endFill();
    	
    	blackBox.graphics.clear();
    	blackBox.graphics.lineStyle(1, border_color);
    	blackBox.graphics.beginFill(color);
    	blackBox.graphics.drawRect(5, 35 + 110*4 + 75*2 + 40*3 + 10*9, _dimx - 200 - 10, 40);
    	blackBox.graphics.endFill();
    	
    	blackBox.graphics.beginFill(0x000000);
      blackBox.graphics.drawRect(5 + _dimx-200-10 - 70, 35+110*4 + 75*2 + 40*4 + 10*9 - 16, 70, 16);
      blackBox.graphics.endFill();
    	
    	whiteBox.graphics.clear();
    	whiteBox.graphics.lineStyle(1, border_color);
    	whiteBox.graphics.beginFill(color);
    	whiteBox.graphics.drawRect(5, 35 + 110*4 + 75*2 + 40*4 + 10*10, _dimx - 200 - 10, 40);
    	whiteBox.graphics.endFill();
    	
    	whiteBox.graphics.beginFill(0xffffff);
      whiteBox.graphics.drawRect(5 + _dimx-200-10 - 70, 35+110*4 + 75*2 + 40*5 + 10*10 - 16, 70, 16);
      whiteBox.graphics.endFill();
      
    }
   
  }
}


